home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp® 2.0.1 Tutorial / Chapter 14 / UIconEdit.p < prev   
Encoding:
Text File  |  1990-10-25  |  6.2 KB  |  206 lines  |  [TEXT/MPS ]

  1. {Copyright © 1989 by Apple Computer, Inc.  All rights reserved.}
  2.  
  3. UNIT UIconEdit;
  4.  
  5.  
  6. INTERFACE
  7.  
  8.  
  9. USES
  10.     { • MacApp }
  11.     UMacApp,
  12.     
  13.     { • Toolbox }
  14.     ToolUtils;
  15.     
  16.     
  17. CONST kSignature = 'ICED';
  18.       kFileType = 'IDOC'; 
  19.  
  20.  
  21. TYPE 
  22.     TIconApplication = OBJECT(TApplication)
  23.  
  24.         PROCEDURE TIconApplication.IIconApplication(iconFileType: OSType);
  25.             {Initializes the application and globals.}
  26.  
  27.         FUNCTION  TIconApplication.DoMakeDocument(itsCmdNumber: CmdNumber): TDocument; OVERRIDE;
  28.             { Creates a document of type TIconDocument and returns a reference to it.}
  29.  
  30.     END;
  31.  
  32.  
  33.     TIconDocument = OBJECT(TDocument)
  34.     
  35.         fIconBitMap:        TIconBitMap;        { The document’s icon object.             }
  36.  
  37.         PROCEDURE TIconDocument.IIconDocument;
  38.             { Initializes the document. }
  39.  
  40.         PROCEDURE TIconDocument.Free; OVERRIDE;
  41.             { Frees allocated memory when the document is closed. }
  42.  
  43.         PROCEDURE TIconDocument.DoInitialState; OVERRIDE;
  44.             { Sets the document's data to represent a "new" document. }
  45.  
  46.         PROCEDURE TIconDocument.DoMakeViews (forPrinting: BOOLEAN); OVERRIDE;
  47.             { Creates the window and view objects when an icon document is opened.}
  48.  
  49.         PROCEDURE TIconDocument.RedrawViews;
  50.             { Causes all views representing this document to be redrawn. }
  51.  
  52.         PROCEDURE TIconDocument.DoSetupMenus; OVERRIDE;
  53.             { Sets the state of the menu items to which this class responds. }
  54.  
  55.         FUNCTION  TIconDocument.DoMenuCommand (aCmdNumber: CmdNumber): TCommand; OVERRIDE;
  56.             { Handles menu items specific to this class. }
  57.  
  58.         PROCEDURE TIconDocument.InvertIcon;
  59.             { Inverts the bits of this document's icon and redraw its views.  }
  60.  
  61.         PROCEDURE TIconDocument.Fields (PROCEDURE DoToField (fieldName: Str255;
  62.                                                                 fieldAddr: Ptr;
  63.                                                                 fieldType: INTEGER)); OVERRIDE;
  64.  
  65.     END;
  66.     
  67.  
  68.  
  69.  
  70.     TIconView = OBJECT(TView)
  71.  
  72.         fMagnification:        INTEGER;            { No. of times to magnify the icon.        }
  73.         fIconDocument:        TIconDocument;        { Reference to the view's icon document.}
  74.  
  75.         PROCEDURE TIconView.IRes (itsDocument: TDocument; itsSuperView: TView;
  76.                                       VAR itsParams: Ptr); OVERRIDE;
  77.             { Initializes the view from a resource template. }
  78.  
  79.         PROCEDURE TIconView.CalcMinSize (VAR minSize: VPoint); OVERRIDE;
  80.             { Returns the view's minimum size. }
  81.  
  82.         PROCEDURE TIconView.Draw (area: Rect); OVERRIDE;
  83.             { Draws this view. }
  84.  
  85.         PROCEDURE TIconView.DrawBit (theBit: Point; turnBitOn: BOOLEAN);
  86.             { Draws the given bit to the given state. }
  87.  
  88.         PROCEDURE TIconView.DoSetupMenus; OVERRIDE;
  89.             { Sets the state of the menu items to which this class responds. }
  90.  
  91.         FUNCTION  TIconView.DoMenuCommand (aCmdNumber: CmdNumber): TCommand; OVERRIDE;
  92.             { Handles menu items specific to this class. }
  93.  
  94.         PROCEDURE TIconView.SetMagnification (magnification: INTEGER);
  95.             { Sets the view's magnification. }
  96.  
  97.         FUNCTION  TIconView.DoMouseCommand (VAR theMouse: Point; VAR info: EventInfo;
  98.                                                 VAR hysteresis: Point): TCommand; OVERRIDE;
  99.             { Handle mouse clicks in this view. }
  100.             
  101.         FUNCTION  TIconView.PointToBit (thePoint: Point; VAR iconBit: Point): BOOLEAN;
  102.             { Converts the given mouse point to an icon bit. }
  103.             
  104.         PROCEDURE TIconView.Fields (PROCEDURE DoToField (fieldName: Str255;
  105.                                                             fieldAddr: Ptr;
  106.                                                             fieldType: INTEGER)); OVERRIDE;
  107.  
  108.     END;
  109.  
  110.  
  111.  
  112.     TInvertCommand = OBJECT(TCommand)
  113.  
  114.         fIconDocument:        TIconDocument;        { The document affected by this command.}
  115.  
  116.         PROCEDURE TInvertCommand.IInvertCommand (itsIconDocument: TIconDocument);
  117.             { Initializes this command, associates it with the given document. }
  118.  
  119.         PROCEDURE TInvertCommand.DoIt; OVERRIDE;
  120.             { Implements the command's action by calling the document's Invert method. }
  121.  
  122.         PROCEDURE TInvertCommand.RedoIt; OVERRIDE;
  123.             { Redoes the command's action by calling the document's Invert method. }
  124.  
  125.         PROCEDURE TInvertCommand.UndoIt; OVERRIDE;
  126.             { Undoes the command's action by calling the document's Invert method. }
  127.         
  128.     END;
  129.  
  130.  
  131.     
  132.     TDrawCommand = OBJECT(TCommand)
  133.  
  134.         fIconDocument:        TIconDocument;        { The document affected by this command.}
  135.         fIconView:            TIconView;            { The view in which this command draws.    }
  136.         fIconBitMap:        TIconBitMap;        { The icon in which drawing takes place.}
  137.         fTurnBitsOn:        BOOLEAN;            { Whether to draw bits black or white.    }
  138.  
  139.         PROCEDURE TDrawCommand.IDrawCommand (itsIconView: TIconView);
  140.             { Initializes the command and associates it with a view. }
  141.  
  142.         PROCEDURE TDrawCommand.TrackConstrain(anchorPoint, previousPoint: VPoint;
  143.                                                 VAR nextPoint: VPoint); OVERRIDE;
  144.             { Constrains the mouse to be within the icon in the edit view by
  145.                 factoring out the margins. }
  146.  
  147.         PROCEDURE TDrawCommand.TrackFeedback(anchorPoint, nextPoint: VPoint;
  148.                                               turnItOn, mouseDidMove: BOOLEAN); OVERRIDE;
  149.             { Overridden to avoid standard feedback. }
  150.  
  151.         FUNCTION  TDrawCommand.TrackMouse(aTrackPhase: TrackPhase;
  152.                                           VAR anchorPoint, previousPoint, nextPoint: VPoint;
  153.                                           mouseDidMove: BOOLEAN): TCommand; OVERRIDE;
  154.             { Tracks the mouse. }
  155.     END;
  156.  
  157.  
  158.  
  159.     TIconBitMap = OBJECT(TObject)
  160.  
  161.         fDataHandle:    Handle;                { Handle to the icon's bit map.            }
  162.  
  163.         PROCEDURE TIconBitMap.IIconBitMap;
  164.             { Initialize the IconBitMap object and allocate space for its data. }
  165.  
  166.         PROCEDURE TIconBitMap.Free; OVERRIDE;
  167.             { Free the icon's bit map. }
  168.             
  169.         PROCEDURE TIconBitMap.SetIconBitMap(theBitMap : Handle);
  170.             { Set the contents of the icon bit map to the new bit map. }
  171.             
  172.         PROCEDURE TIconBitMap.Clear;
  173.             { Clear the icon map by setting its bits to zero. }
  174.             
  175.         PROCEDURE TIconBitMap.Invert;
  176.             { Invert the icon's bit map. }
  177.             
  178.         PROCEDURE TIconBitMap.IconBitToWordBit (iconBit: Point; VAR word, bit: INTEGER);
  179.             { Convert icon bit numbers to the corresponding word and bit number. }
  180.             
  181.         FUNCTION TIconBitMap.GetBit(iconBit: Point): BOOLEAN;
  182.             { Return the state of the given bit. }
  183.             
  184.         PROCEDURE TIconBitMap.SetBit(iconBit: Point; turnBitOn: BOOLEAN);
  185.             { Set the state of the given bit as indicated. }
  186.  
  187.         PROCEDURE TIconBitMap.Draw (area: Rect);
  188.             { Draw the icon's bit map. }
  189.             
  190.         FUNCTION TIconBitMap.Copy: TIconBitMap;
  191.             { Create a new icon object which is a copy of itself. }
  192.             
  193.         PROCEDURE TIconBitMap.CopyDataTo (anIcon: TIconBitMap);
  194.             { Copy icon data to an existing icon object. }
  195.             
  196.         PROCEDURE TIconBitMap.Fields (PROCEDURE DoToField (fieldName: Str255;
  197.                                                               fieldAddr: Ptr;
  198.                                                               fieldType: INTEGER)); OVERRIDE;
  199.     END;
  200.  
  201.  
  202. IMPLEMENTATION
  203.  
  204.     {$I UIconEdit.inc1.p}
  205.  
  206. END.